import requests
import  os

DOWNLOAD_DIR= 'D:/t1'
def download_video_content() -> None:
    """
    下载视频内容并保存到本地。
    
    Args:
        video_url (str): 视频下载的 URL。
        title (str): 视频的标题，用于命名文件。
        headers (Dict[str, str]): HTTP 请求头，包含 Cookie、User-Agent 和 Referer。

    """
    video_url='https://www.douyin.com/aweme/v1/play/?video_id=v0200fg10000ctij01fog65ok4dijbv0\u0026line=0\u0026file_id=44360b99329c496e97bfd45faf7e8a6d\u0026sign=ccc78568d25e3c09ac981bf49ef8f16d\u0026is_play_url=1\u0026source=PackSourceEnum_AWEME_DETAIL'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
        'Referer': 'https://www.douyin.com/video/7451115593245232434',
        # 'Host':'www.douyin.com',
        'Cookie':'ttwid=1%7Cx5D0vQpNGRh-VThjOv-lvaIiCj-7XcoMbo5NpY4tc90%7C1733318492%7Cff1a93be6f1c59a311280963ff2dc0fce71bf433b19ec6ed58ee5f7976609760; UIFID_TEMP=c4a29131752d59acb78af076c3dbdd52744118e38e80b4b96439ef1e20799db0d2714d736a9cbb7c85eb924d6a72982f6aa899a921be1281e847583768f90cde8b32ed7291fc564e94c67b96faad7ee6; s_v_web_id=verify_m49x2x13_qtyQSLmu_pXyh_4nkW_97ot_sBmJusnNhwcO; hevc_supported=true; fpk1=U2FsdGVkX1+vPSpbWC0u4UmMjBXebQzpAbETWOcG4jFS7DJv+ThUGJbuQawFNd+kLt8Wlz1QhSweEi2N253fNg==; fpk2=f51bb482c660d0eeadd1f058058a2b35; passport_csrf_token=f42fdd6621312753df3e31873ef229a6; passport_csrf_token_default=f42fdd6621312753df3e31873ef229a6; bd_ticket_guard_client_web_domain=2; d_ticket=8666c9b0b12dc6d7e412ac8d69c7bd2649da4; n_mh=9lcg3bH8RZXH1WoCKEpgv_ZdgN-5YzyMtaFY5_bHtwM; passport_auth_status=3561dc9a93eb2afc654a30adc137db25%2C; passport_auth_status_ss=3561dc9a93eb2afc654a30adc137db25%2C; is_staff_user=false; UIFID=c4a29131752d59acb78af076c3dbdd52744118e38e80b4b96439ef1e20799db0d2714d736a9cbb7c85eb924d6a72982fd25c55f043bcde2662850887b70692a6e7ffc7e68526c59e3c1a1fd9a7c94c5690412913530b1ee6fb51e8d44fbbd677cb2689b6414942394d0a497b9daa5269d5a7aad78a91276771783b27e5b17ea7a673bae079dde24d0a2712f9f245b107aa87b35b75e9851eef3af4ab710abdcc; SelfTabRedDotControl=%5B%5D; _bd_ticket_crypt_doamin=2; __security_server_data_status=1; store-region=cn-gd; store-region-src=uid; passport_mfa_token=CjfcpBcMCNEESPKKRXEb4u0pVrIn0lWqEevOPCgAHroYMEwhBrVtOu4zkquAmKKcCd99cs2XEKqWGkoKPLPR3rtBfuxlrkzh3qp9PCnJ4USpc7It1HMkSa0IzvNmkPXHnK3EmG2F6XYuj5w5s6ydp%2BrXx9InaLTgYxCnpeMNGPax0WwgAiIBAyqSP4c%3D; passport_assist_user=CkEZl75CCWklHCX7i2VpNx3wKoC7vrdyB2q0IaBNffuufb8JzpmehVDx49sc-zTNHN1kgMDOmUzZUJDS8jKA_wmBeBpKCjx9QkKYq9xJpqTBaEWU206bP_LYOnNPQiVHks8lycmKoHjn5NjSlThQscvHTrRaBN7LYzJlhaUziBbyjJAQgKfjDRiJr9ZUIAEiAQOHoCgc; sso_uid_tt=5642e8b63ff42c9a02539a381e68a201; sso_uid_tt_ss=5642e8b63ff42c9a02539a381e68a201; toutiao_sso_user=0fbc709c84cc94db8f8addaa218ad43c; toutiao_sso_user_ss=0fbc709c84cc94db8f8addaa218ad43c; sid_ucp_sso_v1=1.0.0-KGM1MWQ2MGM3Mjc1MzM0OTA5NjdkYzk1YmU5ZjY5ZmM3NThkOTUyYzcKIQiny4D8iozwAhDu5ca6BhjvMSAMMJLxq4AGOAVA-wdIBhoCbGYiIDBmYmM3MDljODRjYzk0ZGI4ZjhhZGRhYTIxOGFkNDNj; ssid_ucp_sso_v1=1.0.0-KGM1MWQ2MGM3Mjc1MzM0OTA5NjdkYzk1YmU5ZjY5ZmM3NThkOTUyYzcKIQiny4D8iozwAhDu5ca6BhjvMSAMMJLxq4AGOAVA-wdIBhoCbGYiIDBmYmM3MDljODRjYzk0ZGI4ZjhhZGRhYTIxOGFkNDNj; login_time=1733407470094; uid_tt=79c0f6bc231cf51d7728ec7d88f99d63; uid_tt_ss=79c0f6bc231cf51d7728ec7d88f99d63; sid_tt=56c1628d8cb98b7b69fddad34f903c9f; sessionid=56c1628d8cb98b7b69fddad34f903c9f; sessionid_ss=56c1628d8cb98b7b69fddad34f903c9f; _bd_ticket_crypt_cookie=b71e4535fd98112e30c03011467f01cd; sid_guard=56c1628d8cb98b7b69fddad34f903c9f%7C1733407475%7C5183998%7CMon%2C+03-Feb-2025+14%3A04%3A33+GMT; sid_ucp_v1=1.0.0-KDNlYzkzNjNlODYyNjliNjNiZTg5ODEyMWVjMTQxZDljZGI4YTJjNDkKGwiny4D8iozwAhDz5ca6BhjvMSAMOAVA-wdIBBoCbGYiIDU2YzE2MjhkOGNiOThiN2I2OWZkZGFkMzRmOTAzYzlm; ssid_ucp_v1=1.0.0-KDNlYzkzNjNlODYyNjliNjNiZTg5ODEyMWVjMTQxZDljZGI4YTJjNDkKGwiny4D8iozwAhDz5ca6BhjvMSAMOAVA-wdIBBoCbGYiIDU2YzE2MjhkOGNiOThiN2I2OWZkZGFkMzRmOTAzYzlm; dy_swidth=1368; dy_sheight=912; is_dash_user=1; xgplayer_device_id=60610787864; xgplayer_user_id=62352243435; pwa2=%220%7C0%7C2%7C0%22; publish_badge_show_info=%220%2C0%2C0%2C1734530025178%22; download_guide=%223%2F20241218%2F0%22; csrf_session_id=fe9c71cda014a56c379f25dc9d94de95; strategyABtestKey=%221734855799.619%22; biz_trace_id=ad13b74f; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Atrue%2C%22volume%22%3A0.01%7D; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAAVA3A2arpO9wh8jHPfTq_EcwzLXD4-uxeocVwLI8YA8kOOPvRIEnjupp_Hfr69Mvz%2F1734883200000%2F0%2F0%2F1734859252260%22; __ac_nonce=06767e5f00006e7a8a835; __ac_signature=_02B4Z6wo00f01DwAEfgAAIDB41vitj2-imw8IBVAAGhuec; IsDouyinActive=true; home_can_add_dy_2_desktop=%220%22; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1368%2C%5C%22screen_height%5C%22%3A912%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A4%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A1.3%2C%5C%22effective_type%5C%22%3A%5C%223g%5C%22%2C%5C%22round_trip_time%5C%22%3A400%7D%22; odin_tt=11b8aa52d77d99c95d5b63b586d7a90a10ae198ba4ef8d2549e60f3854d79699cc5e8c4c194f4c2662424c7c60162c7e; FOLLOW_LIVE_POINT_INFO=%22MS4wLjABAAAAVA3A2arpO9wh8jHPfTq_EcwzLXD4-uxeocVwLI8YA8kOOPvRIEnjupp_Hfr69Mvz%2F1734883200000%2F0%2F1734862328330%2F0%22; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCQ3VONXRhZHhONkdmYllSSzFJamxKVURZYlVCZVZxcmFRWHFWSk1tTkZRaENnWUJpN1JtTjVFRDBRSnNWdXY2bmwxZzNaS0krOEpWeVcrcjZlamlnMXM9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoyfQ%3D%3D; passport_fe_beating_status=true'
    }
    proxy = {
            'http': 'http://127.0.0.1:8888',
            'https': 'http://127.0.0.1:8888',
        }
    try:
        response = requests.get(video_url, timeout=10,headers=headers,proxies=proxy,verify=False)
        # print(response.content)
        response.raise_for_status()
        file_path = os.path.join(DOWNLOAD_DIR, '3.mp4')
        with open(file_path, 'wb') as f:
            f.write(response.content)
        print(f"已下载并保存视频: {file_path}")
        # res = requests.get(video_url, headers=headers,proxies=proxy,verify=False)
        # print(res.content)

    except requests.RequestException as e:
        print(f"下载视频失败: {e}")
    except Exception as e:
        print(f"保存视频时发生错误: {e}")

if __name__ == "__main__":
    download_video_content()